package com.weixing.mall.provider.controller.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.orm.MPage;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.api.model.enums.OrderTypeEnum;
import com.weixing.mall.provider.api.service.AgentServiceRpc;
import com.weixing.mall.provider.model.dto.OrderAuditDto;
import com.weixing.mall.provider.model.enums.OrderStateEnum;
import com.weixing.mall.provider.model.query.AgentOrderQuery;
import com.weixing.mall.provider.model.query.CustomerOrderQuery;
import com.weixing.mall.provider.model.query.FrontCustomerOrderQuery;
import com.weixing.mall.provider.model.vo.KefuAuditOrderVo;
import com.weixing.mall.provider.model.vo.SalesAchiVo;
import com.weixing.mall.provider.service.IKefuOrderService;
import com.weixing.mall.provider.service.IOrderOperationService;
import com.weixing.mall.provider.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 前端客服订单管理API
 *
 * @author  siashan
 * @date  2019/11/12 10:56
 * @since  1.0
 */
@RestController
@RequestMapping("front/kefu")
public class FrontKefuOrderController extends BaseController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrderOperationService orderOperationService;
    @Autowired
    private AgentServiceRpc agentServiceRpc;
    @Autowired
    private IKefuOrderService kefuOrderService;

    @ApiOperation(value = "订单列表查询")
    @PostMapping("")
    public Result selectList(@SysInfo SysAuth auth, @RequestBody FrontCustomerOrderQuery frontCustomerOrderQuery) {
        return ResultUtil.success(orderService.selectKefuOrderList(initMpPage(),frontCustomerOrderQuery, auth.getUid()));
    }

    @ApiOperation(value = "订单详情")
    @PostMapping("seachDetails/{id}")
    public Result selectDetails(@PathVariable Long id) {
        return ResultUtil.success(orderService.selectFrontCustomerOrderDetails(id));
    }

    @ApiOperation(value = "订单审核")
    @PostMapping("audit")
    public Result audit(@SysInfo SysAuth auth,@RequestBody OrderAuditDto orderAuditDto) {
        orderOperationService.customerAudit(orderAuditDto, auth);
        return ResultUtil.success();
    }

    @ApiOperation(value = "获取当前客服下面的代理列表")
    @GetMapping("agentList")
    public Result selectList(@SysInfo SysAuth auth) {
        return ResultUtil.success(agentServiceRpc.selectByCustomerId(auth.getUid()));
    }


    /**
     * 方法描述: 客服报表
     *
     * @Author Small
     * @Date 2020/5/21 19:42
     * @return com.weixing.mall.base.wrapper.Result
     */
    @ApiOperation(value = "客服报表")
    @PostMapping("sales/agent/{type}")
    public Result salesOfAgent(@PathVariable OrderTypeEnum type, @RequestBody AgentOrderQuery query) {
        IPage<SalesAchiVo> page = kefuOrderService.salesOfAgent(initMpPage(),type,query);
        return ResultUtil.success(page);
    }



    /**
     * 方法描述: 客服主管报表
     *
     * @Author Small
     * @Date 2020/5/21 19:42
     * @return com.weixing.mall.base.wrapper.Result
     */
    @ApiOperation(value = "客服主管报表")
    @PostMapping("sales/kefu/{type}")
    public Result salesOfKefu(@PathVariable OrderTypeEnum type, @RequestBody AgentOrderQuery query) {
        MPage<SalesAchiVo> page = kefuOrderService.salesOfKefu(initMpPage(),type,query);
        return ResultUtil.success(page);
    }

    /**
     * 已拒绝订单
     *
     * @param  query 查询参数
     * @return 订单列表
     */
    @GetMapping("rejectList")
    public Result<IPage<KefuAuditOrderVo>> rejectList(CustomerOrderQuery query) {
        query.setOrderStatus(OrderStateEnum.REJECT);
        return ResultUtil.success(kefuOrderService.toAudit(initMpPage(), query));
    }

}
